package com.exam.utils;

import java.util.Map;

import com.exam.bean.privilege.SystemPrivilegePK;
import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;

public class SystemPrivilegePKConverter extends DefaultTypeConverter {

	@SuppressWarnings("unchecked")
	@Override
	public Object convertValue(Map<String,Object> context,Object value, Class toType) {
		try {
			if(toType==SystemPrivilegePK.class){
				String idstr = (String)value;
				String[] idkey = idstr.split(",");
				if(idkey.length==2){
					return new SystemPrivilegePK(idkey[0], idkey[1]);
				}
				else return null;
			}
			else if(toType==String.class){
				SystemPrivilegePK pk=(SystemPrivilegePK)value;
				return pk.getClass()+","+pk.getPrivilegeValue();
			}
		}catch (Exception e) {}
		return null;
	}

}
